package com.xishu.controller;

import com.xishu.entity.customer.MarketEmailTemplate;
import com.xishu.response.ResponseData;
import com.xishu.response.VerifyUtil;
import com.xishu.service.CommonService;
import com.xishu.service.CompanyService;
import com.xishu.service.CustomerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 生日邮件模板
 */
@RestController
public class MarketEmailTemplateDao {
    private CustomerService customerService = CustomerService.getInstance();
    private CompanyService companyService = CompanyService.getInstance();
    private CommonService commonService = CommonService.getInstance();

    @ApiOperation(value = "创建生日邮件模板")
    @PostMapping(value = ("/market/email/template"), produces = ("application/json;charset=UTF-8"))
    public ResponseData create(@RequestBody MarketEmailTemplate marketEmailTemplate) throws Exception {
        Long companyId = marketEmailTemplate.getCompanyId();
        companyService.findCompanyById(companyId);
        boolean own = companyService.ownCompany(companyId);
        VerifyUtil.verify(() -> own);

        return commonService.createObject(marketEmailTemplate);
    }

    @ApiOperation(value = "修改生日邮件模板")
    @PutMapping(value = ("/market/email/modify"), produces = ("application/json;charset=UTF-8"))
    public ResponseData modify(@RequestBody MarketEmailTemplate marketEmailTemplate) {
        return ResponseData.emptyResponse();
    }

}
